﻿using System.Diagnostics;
using System.Windows.Forms;
using System.Timers;
using System;


//
//
// http://blogs.msdn.com/shawnhar/archive/2007/07/25/understanding-gametime.aspx
// Mise en place d'un timer : http://www.opentk.com/doc/chapter/2/glcontrol
//
namespace ArcEngine.Time
{

	/// <summary>
	/// Snapshot of the game timing states
	/// </summary>
	static public class GameTime
	{

		/// <summary>
		/// 
		/// </summary>
		static GameTime()
		{
			stopwatch.Start();
		}


		/// <summary>
		/// Updates game time states
		/// </summary>
		/// <returns>Elapsed time in ms</returns>
		static internal long Update()
		{
			long now = stopwatch.ElapsedMilliseconds;

			elapsed = now - lastUpdate;
			lastUpdate = now;

			

			return elapsed;
		}



		#region Properties

		/// <summary>
		/// Stopwatch timer
		/// </summary>
		static Stopwatch stopwatch = Stopwatch.StartNew();


		/// <summary>
		/// Last time an update occured
		/// </summary>
		private static long lastUpdate = 0;
		

		/// <summary>
		/// The amount of elapsed game time since the last update
		/// </summary>
		static public long Elapsed
		{
			get
			{
				return elapsed;
			}
		}
		static long elapsed = 0;




		/// <summary>
		/// Gets/Sets the desired framerate
		/// </summary>
		static public int FPS
		{
			get
			{
				return fps;
			}
			set
			{
				fps = value;
			}
		}
		static int fps = 60;


		/// <summary>
		/// Time slice
		/// </summary>
		static public float FrameTime
		{
			get
			{
				return Elapsed / 100.0f;
			}
		}

/*
		/// <summary>
		/// Gets a value indicating that the game loop is taking longer than 
		/// its TargetElapsedTime. In this case, the game loop can be considered 
		/// to be running too slowly and should do something to "catch up." 
		/// </summary>
		static public bool IsRunningSlowly
		{
			get
			{
				return isRunningSlowly;
			}
		}
		static bool isRunningSlowly = false;
*/

		/// <summary>
		/// The amount of game time since the start of the game.
		/// </summary>
		static public long TotalGameTime
		{
			get
			{
				return stopwatch.ElapsedMilliseconds;
			}
		}

		#endregion
	}

}
